/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.states;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import ace.system.BitmapFont;
import ace.system.StateManager;
import ace.system.StringManager;
import ace.system.Utilities;
import ace.system.sound.SFXPlayer;

/**
 *
 * @author TimotiusNC
 */
public class StateCredit extends GameState {
	public StateCredit(){
		super(GameState.CREDITS, StateManager.instance().getBackgroundImage());
		
		//Not drawn
		m_Drawn = false;
		
		//Create image
		try {
			m_Creator1Text	= BitmapFont.getFont(BitmapFont.TITLE).renderTransparentText("Listiarso Wastuargo", 0x00000000);
			m_Creator2Text	= BitmapFont.getFont(BitmapFont.TITLE).renderTransparentText("Timotius Nugroho Chandra", 0x00000000);
			m_DevelopedText	= BitmapFont.getFont(BitmapFont.TITLE).renderTransparentText(StringManager.instance().getString("developed"), 0x00000000);
			m_VersionImage	= Image.createImage(Utilities.INTERFACE_FOLDER + "/version.png");
			//m_ReturnImage	= BitmapFont.getFont(BitmapFont.MAIN).renderTransparentText(StringManager.instance().getString("return"), 0x00000000);
			m_Title			= Image.createImage(Utilities.INTERFACE_FOLDER + "/title.png");
			m_Lite			= Image.createImage(Utilities.INTERFACE_FOLDER + "/lite.png");
		} catch (IOException ex) {}
	}

	public void keyPressed(int key){
		//Super
		super.keyPressed(key);

		if (key == -7 || key == 35) { //Is right pressed?
			m_Active = false;
			
			//Back sound effect StateManager.instance().playSFX("/cancel.wav");
			StateManager.instance().getSFXPlayer().playSFX(SFXPlayer.SFX_CANCEL);
		}
	}

	public void update(long time, int keys) {
		//Super
		super.update(time, keys);

		//If button is pressed
		if ((keys & GameCanvas.FIRE_PRESSED) != 0) {
			//Goto GAME state
			m_Active = false;
			
			//Back sound effect StateManager.instance().playSFX("/cancel.wav");
			StateManager.instance().getSFXPlayer().playSFX(SFXPlayer.SFX_CANCEL);
		}
	}

	public void draw(Graphics g) {
		//Skip if drawn
		if (m_Drawn) return;
		
		//Super
		super.draw(g);
		
		//Draw images
		g.drawImage(StateManager.instance().getDarkImage(), 0, 0, Graphics.LEFT | Graphics.TOP);
		g.drawImage(StateManager.instance().getDeveloperImage(), StateManager.instance().getWidth() / 2, StateManager.instance().getHeight() / 2, Graphics.HCENTER | Graphics.VCENTER);

		g.drawImage(m_VersionImage, StateManager.instance().getWidth(), 0, Graphics.RIGHT | Graphics.TOP);
		g.drawImage(m_DevelopedText, 20, (StateManager.instance().getHeight() - StateManager.instance().getDeveloperImage().getHeight()), Graphics.LEFT | Graphics.BOTTOM);
		g.drawImage(m_Creator1Text, StateManager.instance().getWidth() - 20, StateManager.instance().getHeight() - 50, Graphics.RIGHT | Graphics.TOP);
		g.drawImage(m_Creator2Text, StateManager.instance().getWidth() - 20, StateManager.instance().getHeight() - 30, Graphics.RIGHT | Graphics.TOP);

		g.drawImage(m_Title, StateManager.instance().getWidth() / 2, 5, Graphics.HCENTER | Graphics.TOP);
		g.drawImage(m_Lite, StateManager.instance().getWidth() - 10, 35, Graphics.RIGHT | Graphics.TOP);

		//g.drawImage(m_ReturnImage, StateManager.instance().getWidth() - 4, StateManager.instance().getHeight()-4, Graphics.RIGHT | Graphics.BOTTOM);
		
		//Drawn
		m_Drawn = true;		
	}
	
	protected boolean	m_Drawn;
	protected Image		m_Title;
	protected Image		m_Lite;
	protected Image		m_Creator1Text;
	protected Image		m_Creator2Text;
	protected Image		m_DevelopedText;
	protected Image		m_VersionImage;
}
